<?php
namespace App\Middlewares;
use App\Models\UserModel;
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
class RoleMiddleware extends BaseMiddleware{
	public function __invoke(Request $request, Response $response, $next) {
		$urlpath = $request -> getUri() -> getPath();
		$user = new UserModel();
		$ret = $user ->getUserRolePower($_SESSION["loginName"], $urlpath);
		//验证是否具备访问权限
		if ($ret == 0) {
			return $response -> withRedirect($this -> container -> router -> pathFor('Error'));
		} else {
			$response = $next($request, $response);
		}
		return $response;
	}
}
